package com.lcz.audioplayer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;


/**
 * 屏幕亮了，灭了，弹出锁屏页面逻辑
 * 其实这个跟通知处理逻辑一样
 */
public class ScreenLockBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if(action!=null && action.length()>0){
            switch (action){
                //当屏幕灭了
                case Intent.ACTION_SCREEN_OFF:
                    if (PlayerClient.getInstance().getAudioList() == null || PlayerClient.getInstance().getAudioList().isEmpty()) {

                    }else {
                        startScreenLockActivity(context);
                    }

                    break;
                //当屏幕亮了
                case Intent.ACTION_SCREEN_ON:

                    break;
                default:
                    break;
            }
        }
    }
    /**
     * 打开锁屏页面，
     * 有些APP限制了状态，比如只有播放时才走这个逻辑
     */
    private void startScreenLockActivity(Context context) {
//        if(!mIsLocked && isPlaying()){
//            Intent lockScreen = new Intent(this, LockAudioActivity.class);
//            lockScreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            startActivity(lockScreen);
//            BaseConfig.INSTANCE.setLocked(true);
//        }
        Intent lockScreen = new Intent(context, ScreenLockActivity.class);
        lockScreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(lockScreen);
    }
}
